<?php

namespace App\Http\Controllers;
use DB;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class InstallmentController extends BaseController
{
    public function index(){
    	header("Content-type:text/html;charset=utf-8");
    	$period=DB::table('periods')->get();
    	$city=DB::table('city')->where('city_type',2)->limit(10)->get();
    	$stage=DB::table('stage')->get();
    	$work=DB::table('work')->get();
    	$honor=DB::table('honor')->get();
    	$salary=DB::table('salary')->get();
    	$house=DB::table('house')->get();
    	return view("fenqi",[
    		'period'=>$period,
    		'city'=>$city,
    		'stage'=>$stage,
    		'work'=>$work,
    		'honor'=>$honor,
    		'salary'=>$salary,
    		'house'=>$house
    		]);
    }

    public function stage(){
    	$city_id=$_POST['grade'];
    	//echo $city_id;die;
    	$stage=DB::table('city')->where('parent_id',$city_id)->get();
    	echo json_encode($stage);
    }

    public function buyings(){
    	//echo 111;die;
    	$amount=isset($_GET['amount'])?$_GET['amount']:'';
    	$periods=isset($_GET['periods'])?$_GET['periods']:'';
    	$tel=isset($_GET['tel'])?$_GET['tel']:'';
    	$city=isset($_GET['city'])?$_GET['city']:'';
    	$work=isset($_GET['work'])?$_GET['work']:'';
    	$honor=isset($_GET['honor'])?$_GET['honor']:'';
    	$salary=isset($_GET['salary'])?$_GET['salary']:'';
    	$house=isset($_GET['house'])?$_GET['house']:'';
    	$val=DB::table('buying')->insert(array(
    		'amount_money'=>$amount,
    		'periods'=>$periods,
    		'tel'=>$tel,
    		'city_name'=>$city,
    		'work_name'=>$work,
    		'honor_name'=>$honor,
    		'salary_type'=>$salary,
    		'house_status'=>$house
    		));
    	if($val){
    		echo 'ok';
    	}else{
    		echo 'error';
    	}
    }
}
